***** replication code *****

// **** MAIN TABLES **** //

*** table 1 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

bys session: gen count=_n

su pm25_imp temp_imp ur_imp if count==1

replace avg_srtv_latency=avg_srtv_latency/1000
su avg_srtv_latency avg_cpt_correct avg_math_correct_rev avgDS_ML avg_baddeley_correct

*** table 2 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

foreach var of varlist avg_srtv_latency {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}

*** table 3 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

foreach var of varlist avg_srtv_latency {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp ur_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}

foreach var of varlist avg_srtv_latency {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_impBIN1-ur_impBIN5 med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}

*** table 4 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

local studentXs city_of_SP birth_state_SP age18to24 male mother_hgc_hs mother_hgc_colpl father_hgc_hs father_hgc_colpl income_response_rev hhsize_response  all_private all_public stem uni_years_response employed havesmoked100cigs currentlysmoke alcohol_response binge_response exercised ever_airway high_blood_pressure fairpoorgenhealth physical_response mental_response keepyou_response sleep_response sleep_last_night_response time_use_response weight_response height_response

foreach var of varlist avg_srtv_latency {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq `studentXs' med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}

*** table 5 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

sort stu_id, stable
merge stu_id using "U:\Research Files\Brazil Project\replication_gpa.dta"
tab _merge
drop _merge

replace pm25_imp=pm25_imp/10

foreach var of varlist gpa {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq all_private all_public i.entr_year i.major cohort_size pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq all_private all_public i.entr_year i.major cohort_size med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}

*** table 6 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10
replace o3_imp=o3_imp/10

foreach var of varlist avg_srtv_latency {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(o3_imp pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(o3_imp pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(o3_imp pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(o3_imp pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq o3_imp med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(o3_imp pm25_imp med_pm25_imp high_pm25_imp)
}

*** table 7 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10
replace F1pm25_imp=F1pm25_imp/10

foreach var of varlist avg_srtv_latency {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq F1temp_imp F1ur_imp F1temp_imp_sq F1ur_imp_sq F1pm25_imp pm25_imp, cluster(session)
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(F1pm25_imp pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq F1temp_imp F1ur_imp F1temp_imp_sq F1ur_imp_sq F1pm25_imp pm25_imp, cluster(session)
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(F1pm25_imp pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq F1temp_imp F1ur_imp F1temp_imp_sq F1ur_imp_sq F1pm25_imp pm25_imp, cluster(session)
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(F1pm25_imp pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq F1temp_imp F1ur_imp F1temp_imp_sq F1ur_imp_sq F1pm25_imp pm25_imp, cluster(session)
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(F1pm25_imp pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq F1temp_imp F1ur_imp F1temp_imp_sq F1ur_imp_sq F1pm25_imp pm25_imp, cluster(session)
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(F1pm25_imp pm25_imp)
}

*** table 8 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

foreach var of varlist avg_srtv_latency {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (pm25_imp=L1vv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (pm25_imp=L1vv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (pm25_imp=L1vv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (pm25_imp=L1vv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (pm25_imp=L1vv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp)
}

// **** MAIN FIGURES **** //

*** figure 1 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

collapse (mean) pm25_imp, by(session)
 
histogram pm25_imp, frequency ytitle(Number of Days) ylabel(#10) xtitle(Particulate Matter 2.5 (μg/m3)) xlabel(#5)

*** figure 2 ***

clear all
use "U:\Research Files\Brazil Project\Pollution Data\Pollution Data\Cidade Universitaria\environ_cid_uni.dta"
keep date pm25_day

sort date, stable
merge date using "U:\Research Files\Brazil Project\Pollution Data\Pollution Data\pinheiros\environ_pinheiros.dta"
gen pm25_imp=pm25_day
replace pm25_imp=pm25_day_pinheiros if pm25_day==.
keep date pm25_day pm25_imp pm25_day_pinheiros

sort date, stable
merge date using "U:\Research Files\Brazil Project\Pollution Data\Pollution Data\marg_tiete\environ_marginal_tiete.dta"
tab _merge
replace pm25_imp=pm25_day_marginal_tiete if (pm25_day==. & pm25_day_pinheiros==.)
su pm25_imp
keep date pm25_day pm25_imp pm25_day_pinheiros pm25_day_marginal_tiete

sort date, stable
merge date using "U:\Research Files\Brazil Project\session_dates.dta"
tab _merge
compress

twoway (scatter pm25_imp date, mcolor(dimgray) ytitle(Particulate Matter 2.5 (μg/m3))) (scatter pm25_imp date if session!=., mcolor(gray) msymbol(triangle))

*** figure 3 ***

*NOTE: no data used to generate this figure

*** figure 4 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

foreach var of varlist avg_srtv_latency avg_cpt_correct avg_math_correct_rev avgDS_ML avg_baddeley_correct pm25_imp {

reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq
predict `var'_res, res

}

collapse (mean) avg_srtv_latency_res avg_cpt_correct_res avg_math_correct_rev_res avgDS_ML_res avg_baddeley_correct_res pm25_imp_res, by(session)

foreach var of varlist avg_srtv_latency_res avg_cpt_correct_res avg_math_correct_rev_res avgDS_ML_res avg_baddeley_correct_res pm25_imp {

egen m_`var'=mean(`var')
egen s_`var'=sd(`var')
gen `var'_s=(`var'-m_`var')/(s_`var')
drop m_`var' s_`var'
}

label var avg_srtv_latency_res_s "SRTT (St. Residual)"
label var avg_cpt_correct_res_s "CPT (St. Residual)"
label var avg_math_correct_rev_res_s "MATH (St. Residual)"
label var avgDS_ML_res "DS (St. Residual)"
label var avg_baddeley_correct_res_s "BAD (St. Residual)"
label var pm25_imp_res_s "PM2.5 (St. Residual)"

rename avg_srtv_latency_res_s SRTT 
rename avg_cpt_correct_res_s CPT
rename avg_math_correct_rev_res_s MATH
rename avgDS_ML_res DS
rename avg_baddeley_correct_res_s BAD
rename pm25_imp_res_s PM25

aaplot SRTT PM25, lopts(lc(black)) msymbol(O)
aaplot CPT PM25, lopts(lc(black)) msymbol(O)
aaplot MATH PM25, lopts(lc(black)) msymbol(O)
aaplot DS PM25, lopts(lc(black)) msymbol(O)
aaplot BAD PM25, lopts(lc(black)) msymbol(O)

// **** APPENDIX TABLES **** //

*** appendix table 1 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq dv_day_marginal_tiete, cluster(session)
gen wind_data_avail=1==(e(sample)==1)

bys session: gen count=_n
su pm25_imp temp_imp ur_imp vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete if count==1 & wind_data_avail==1

*** appendix table 2 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

pwcorr avg_srtv_latency avg_cpt_correct avg_math_correct_rev avgDS_ML avg_baddeley_correct, sig

*** appendix table 3 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

orth_out city_of_SP birth_state_SP age18to24 age25plus male mother_hgc_hs mother_hgc_colpl father_hgc_hs father_hgc_colpl income_response_rev hhsize_response exam_response all_private all_public stem uni_years_response employed havesmoked100cigs currentlysmoke alcohol_response binge_response exercised ever_airway current_airway high_blood_pressure fairpoorgenhealth physical_response mental_response keepyou_response sleep_response sleep_last_night_response time_use_response weight_response height_response bmi overweight obese selfass_response, by(low_pm25_imp med_pm25_imp high_pm25_imp) pcompare se vce(cluster session) count

*** appendix table 4 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

foreach var of varlist MAP PUL O2 {
eststo m1: qui: reg `var' age male high_blood_pressure, cluster(session) 
estout m1, cells(b(star fmt(3)) se(par fmt(4))) stats(r2 r2_a N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(age male high_blood_pressure)
}

*** appendix table 5 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq dv_day_marginal_tiete, cluster(session)
gen wind_data_avail=1==(e(sample)==1)

eststo m1: qui: reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq if wind_data_avail==1, cluster(session)
eststo m2: qui: reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq vv_day_marginal_tiete if wind_data_avail==1, cluster(session)
eststo m3: qui: reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq L1vv_day_marginal_tiete if wind_data_avail==1, cluster(session)
eststo m4: qui: reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq dv_day_marginal_tiete if wind_data_avail==1, cluster(session)
eststo m5: qui: reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq L1dv_day_marginal_tiete if wind_data_avail==1, cluster(session)
eststo m6: qui: reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete if wind_data_avail==1, cluster(session)
estout m1 m2 m3 m4 m5 m6, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete)

*** appendix table 6 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq dv_day_marginal_tiete, cluster(session)
gen wind_data_avail=1==(e(sample)==1)

eststo m1: qui: reg avg_srtv_latency dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp if wind_data_avail==1, cluster(session)
eststo m2: qui: reg avg_cpt_correct dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp if wind_data_avail==1, cluster(session) 
eststo m3: qui: reg avg_math_correct_rev dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp if wind_data_avail==1, cluster(session) 
eststo m4: qui: reg avgDS_ML dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp if wind_data_avail==1, cluster(session)
eststo m5: qui: reg avg_baddeley_correct dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp if wind_data_avail==1, cluster(session) 
estout m1 m2 m3 m4 m5, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp)

*** appendix table 7 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

foreach var of varlist avg_srtv_latency {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (med_pm25_imp high_pm25_imp=vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_cpt_correct {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (med_pm25_imp high_pm25_imp=vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_math_correct_rev {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (med_pm25_imp high_pm25_imp=vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(med_pm25_imp high_pm25_imp)
}
foreach var of varlist avgDS_ML {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (med_pm25_imp high_pm25_imp=vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(med_pm25_imp high_pm25_imp)
}
foreach var of varlist avg_baddeley_correct {
eststo m1: qui: ivreg2 `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq (med_pm25_imp high_pm25_imp=vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete), cluster(session) partial(dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq) 
estout m1, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(med_pm25_imp high_pm25_imp)
}

*** appendix table 8 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

reg pm25_imp dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq dv_day_marginal_tiete, cluster(session)
gen wind_data_avail=1==(e(sample)==1)

eststo m1: qui: reg avg_srtv_latency dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp if wind_data_avail==1, cluster(session)
eststo m2: qui: reg avg_cpt_correct dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp if wind_data_avail==1, cluster(session) 
eststo m3: qui: reg avg_math_correct_rev dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp if wind_data_avail==1, cluster(session) 
eststo m4: qui: reg avgDS_ML dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp if wind_data_avail==1, cluster(session)
eststo m5: qui: reg avg_baddeley_correct dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp if wind_data_avail==1, cluster(session) 
estout m1 m2 m3 m4 m5, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(med_pm25_imp high_pm25_imp)

*** appendix table 9 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
su MAP PUL O2

*** appendix table 10 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

pwcorr MAP PUL O2, sig

*** appendix table 11 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace pm25_imp=pm25_imp/10

foreach var of varlist MAP {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist PUL {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}
foreach var of varlist O2 {
eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}

*** appendix table 12 ***

clear all
use "U:\Research Files\Brazil Project\replication_major_gpa.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000

eststo m1: qui: reg avg_gpa_same_major i.entr_year cohort_size stem avg_srtv_latency, cluster(session)
eststo m2: qui: reg avg_gpa_same_major i.entr_year cohort_size stem avg_cpt_correct, cluster(session)
eststo m3: qui: reg avg_gpa_same_major i.entr_year cohort_size stem avg_math_correct_rev, cluster(session)
eststo m4: qui: reg avg_gpa_same_major i.entr_year cohort_size stem avgDS_ML, cluster(session)
eststo m5: qui: reg avg_gpa_same_major i.entr_year cohort_size stem avg_baddeley_correct, cluster(session)
eststo m6: qui: reg avg_gpa_same_major i.entr_year cohort_size stem avg_srtv_latency avg_cpt_correct avg_math_correct_rev avgDS_ML avg_baddeley_correct, cluster(session)
estout m1 m2 m3 m4 m5 m6, cells(b(star fmt(3)) se(par fmt(4))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01)

*** appendix table 13 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

foreach var of varlist selfass_response current_airway {

eststo m1: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq pm25_imp, cluster(session)
eststo m2: qui: reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq med_pm25_imp high_pm25_imp, cluster(session)
estout m1 m2, cells(b(star fmt(3)) se(par fmt(3)) p(par fmt(3))) stats(r2 N) starlevels(* 0.10 ** 0.05 *** 0.01) keep(pm25_imp med_pm25_imp high_pm25_imp)
}

*** appendix table 14 ***

*NOTE: please see paper for calculations

// **** APPENDIX FIGURES **** //

*** appendix figure 1 ***

*NOTE: no data used to generate this figure

*** appendix figure 2 ***

*NOTE: no data used to generate this figure

*** appendix figure 3 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

collapse (max)  vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete, by(session)

histogram L1dv_day_marginal_tiete, frequency ytitle(Number of Days) xtitle(Lagged Wind Direction - Marginal Tietê) xscale(range(0 360)) xlabel(0 "N" 45 "NE" 90 "E" 135 "SE" 180 "S" 225 "SW" 270 "W" 315 "NW" 360 "N") xline(0 90 180 270 360, lpattern(dash))

*** appendix figure 4 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

collapse (max)  vv_day_marginal_tiete L1vv_day_marginal_tiete dv_day_marginal_tiete L1dv_day_marginal_tiete, by(session)

histogram L1vv_day_marginal_tiete, frequency ytitle(Number of Days) xtitle(Lagged Wind Speed - Marginal Tietê (meters/sec))

*** appendix figure 5 ***

clear all
use "U:\Research Files\Brazil Project\replication_tests.dta", clear

replace avg_srtv_latency=avg_srtv_latency/1000
replace pm25_imp=pm25_imp/10

foreach var of varlist MAP PUL O2 pm25_imp {

reg `var' dow1-dow4 yearmonth1-yearmonth18 temp_imp temp_imp_sq ur_imp ur_imp_sq
predict `var'_res, res

}

collapse (mean) MAP_res PUL_res O2_res pm25_imp_res, by(session)

foreach var of varlist MAP_res PUL_res O2_res pm25_imp {

egen m_`var'=mean(`var')
egen s_`var'=sd(`var')
gen `var'_s=(`var'-m_`var')/(s_`var')
drop m_`var' s_`var'
}

label var MAP_res_s "MAP (St. Residual)"
label var PUL_res_s "PUL (St. Residual)"
label var O2_res_s "O2 (St. Residual)"
label var pm25_imp_res_s "PM2.5 (St. Residual)"

rename MAP_res_s MAP
rename PUL_res_s PUL
rename O2_res_s O2
rename pm25_imp_res_s PM25
aaplot MAP PM25, lopts(lc(black)) msymbol(O)
aaplot PUL PM25, lopts(lc(black)) msymbol(O)
aaplot O2 PM25, lopts(lc(black)) msymbol(O)